package net.kazed.nextaction.database.serialize;

import net.kazed.nextaction.database.GtdContext;
import net.kazed.nextaction.database.Task;

public class ContextXmlSerializer {
   
   private XmlWriter writer;

   /**
    * Constructor.
    * @param writer XML writer.
    */
   public ContextXmlSerializer(XmlWriter writer) {
      super();
      this.writer = writer;
   }

   /**
    * Serialize context.
    * @param context Serialize this context.
    */
   public void serialize(GtdContext context) {
      writer.startElement("context");
      writer.addElement("id", context.getId());
      writer.addElement("parentId", context.getParentContextId());
      writer.addElement("name", context.getName());
      writer.endElement();
   }

   /**
    * Serialize task.
    * @param task Serialize this task.
    */
   public void serialize(Task task) {
      writer.startElement("task");
      writer.addElement("id", task.getId());
      writer.addElement("description", task.getDescription());
      writer.addElement("details", task.getDetails());
      writer.addElement("complete", task.getComplete());
      writer.addElement("contextId", task.getContextId());
      writer.addElement("created", task.getCreated());
      writer.addElement("dueDate", task.getDueDate());
      writer.addElement("modifyDate", task.getModified());
      writer.addElement("order", task.getOrder());
      writer.addElement("parentTaskId", task.getParentTaskId());
      writer.addElement("startDate", task.getStartDate());
      writer.endElement();
   }

}
